/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package front_end;

import csm.uttils.Archive;
import java.io.Serializable;

/**
 *
 * @author gaston
 */
public class Persistence {

    private static String lastPath=null;
    private static String[] lastFiles=null;

    public static void savePath(String path) {
        Persistence.lastPath = path;
        (new Archive("preferences.cfg")).writeObject(new Preferences(Persistence.lastPath, Persistence.lastFiles));
    }

    public static void quequeFile(String file) {
        try {
            getLastFiles();
        } catch (Exception e) {
        }
        if (lastFiles == null) {
            lastFiles = new String[4];
        }
        for (int i = 0; i < lastFiles.length; i++) {
            lastFiles[i] = lastFiles[i + 1];
        }
        lastFiles[lastFiles.length - 1] = file;
        (new Archive("preferences.cfg")).writeObject(new Preferences(Persistence.lastPath, Persistence.lastFiles));
    }

    public static String[] getLastFiles() {
        Persistence.lastFiles = ((Preferences) (new Archive("preferences.cfg")).readObject()).getLastFiles();
        return Persistence.lastFiles;
    }
    public static String getLastPath(){
        try{
        Persistence.lastPath = ((Preferences) (new Archive("preferences.cfg")).readObject()).getLastPath();
        }catch(Exception e){}
        return Persistence.lastPath;

    }
}

class Preferences implements Serializable {

    private String lastPath;
    private String[] lastFiles;

    public Preferences(String lastPath, String[] lastFiles) {
        this.lastPath = lastPath;
        this.lastFiles = lastFiles;
    }

    String[] getLastFiles() {
        return lastFiles;
    }

    String getLastPath() {
        return lastPath;
    }
}
